package com.logic.landseaserver.ws;


import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import com.logic.common.enums.HttpCodeEnum;
import com.logic.common.exception.BusinessException;
import com.logic.common.util.CommonResult;
import com.logic.common.util.CommonResultMap;
import com.logic.landseaserver.domain.ReportStrip;
import com.logic.landseaserver.service.IReportStripService;
import com.logic.landseaserver.service.impl.ReportStripServiceImpl;
import com.logic.landseaserver.ws.dto.ReportStripDTO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Path("/reportStrip")
@Api(value="reportStrip")
public class ReportStripRest {
	
	@Autowired
	private IReportStripService reportStripService;

	@Autowired
	private ReportStripServiceImpl reportStripServiceImpl;
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	//条线报告
	@POST
	@Path("/lineReportForm/list")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "list line report form")
	public Response reportStrip(@ApiParam(value = "param", required = true)@QueryParam("reportProjectId") Integer id){
		CommonResultMap map = new CommonResultMap();
		try {
			String type="月报";
			List<ReportStripDTO> reportStrips = reportStripService.queryreportStrip(id,type);
			map.setData(reportStrips);
			map.setResult(CommonResult.SUCCESS);
		} catch (Exception e) {
		    logger.error("reportStrip error.", e);
			map.setResult(CommonResult.ERROR, e.getMessage());
		}
		return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
	}
	
	//条线报告
	@POST
	@Path("/lineReportForm")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "list line report form")
	public Response reportStripDTO(@ApiParam(value = "param", required = true) @QueryParam("id") Integer id){
		CommonResultMap map = new CommonResultMap();
		try {
			ReportStrip reportStrip = (ReportStrip)reportStripServiceImpl.getObject(id);
			map.setData(reportStrip);
			map.setResult(CommonResult.SUCCESS);
		} catch (Exception e) {
		    logger.error("reportStrip error.", e);
			map.setResult(CommonResult.ERROR, e.getMessage());
		}
		return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
	}
	
	@POST
	@Path("/creat/lineReportForm/list")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "Create a new lineReportForm")
	public Response createLineReportForm(@ApiParam(value = "param", required = true) ReportStrip reportStrip) {
		CommonResultMap map = new CommonResultMap();
		try {
			int id = reportStripService.insert(reportStrip);
			reportStrip.setId(id);
			//map.setData(reportStripService.get(id));
			map.setResult(CommonResult.SUCCESS, "Create success");
		} catch (BusinessException e) {
		    logger.error("createLineReportForm error.", e);
			map.setResult(e);
		}  catch (Exception e) {
		    logger.error("createLineReportForm error.", e);
			map.setResult(CommonResult.ERROR, e.getMessage());
		}
		return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
	}
	
	@DELETE
	@Path("/delete/lineReportForm")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_JSON)
	@ApiOperation(value = "logic delete lineReportForm by set deleted")
	public Response logicDelete(@ApiParam(value = "param", required = true) @QueryParam("reportStripId") String ids) {
		CommonResultMap map = new CommonResultMap();
		try {
			reportStripServiceImpl.delete(ids);
			map.setResult(CommonResult.SUCCESS,"delete reportStrip");
		} catch (Exception e) {
		    logger.error("logicDelete error.", e);
			map.setResult(CommonResult.ERROR, e.getMessage());
		}
		return Response.status(HttpCodeEnum.OK.getCode()).entity(map).build();
	}
	
}
